package com.zut.service.impl;

import com.zut.dao.FoodCategoryDao;
import com.zut.dao.ShopDao;
import com.zut.dao.impl.FoodCategoryDaoImpl;
import com.zut.dao.impl.ShopDaoImpl;
import com.zut.pojo.FoodCategory;
import com.zut.pojo.Shop;
import com.zut.service.FoodCategoryService;
import com.zut.vo.FoodCategoryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张晨
 * @date 2024/9/13 9:54
 * @desc
 */
public class FoodCategoryServiceImpl implements FoodCategoryService {
    private FoodCategoryDao foodCategoryDao = new FoodCategoryDaoImpl();
    private ShopDao shopDao = new ShopDaoImpl();

    @Override
    public List<FoodCategoryVo> selectByShopId(int shopId) {

        List<FoodCategory> foodCategories = foodCategoryDao.selectByShopId(shopId);

        List<FoodCategoryVo> foodCategoryVos = new ArrayList<>();
        for (FoodCategory foodCategory : foodCategories) {

            FoodCategoryVo foodCategoryVo = new FoodCategoryVo();

            BeanUtils.copyProperties(foodCategory,foodCategoryVo);

            Shop shop = shopDao.selectByShopId(shopId);

            foodCategoryVo.setShopName(shop.getShopName());

            foodCategoryVos.add(foodCategoryVo);
        }
        return foodCategoryVos;
    }

    @Override
    public Integer updateById(FoodCategory foodCategory) {
        return foodCategoryDao.updateById(foodCategory);

    }

    @Override
    public Integer delById(Integer categoryId) {
        return foodCategoryDao.deleteById(categoryId);
    }

    @Override
    public Integer add(FoodCategory foodCategory) {
        return foodCategoryDao.insert(foodCategory);
    }
}
